<style type="text/css">
    .hide{display: none;}
    .clear{clear: both;}
    .laydate-time-list{padding-bottom:0;overflow:hidden}
    .laydate-time-list>li{width:50%!important;}
    .laydate-time-list>li:last-child { display: none;}
    .green{color: green;}
    .blue{color: #1E9FFF;}
    .red{color: red;}
    .xian{margin: 5px 0px;height: 1px;width: 100%;clear: both;border-top: 1px dashed #c1c1c1;}
    .h38{height: 38px;line-height: 38px;color: red;}
    .center{text-align: center!important;}
</style>
<script>
    var baseUrl = "<?php echo $baseUrl; ?>?t=1";
</script>

<div class="layui-row search-row" id="search-box">
    <div class="item">
        <div class="row" style="width: 500px">
            <div class="box">
                <span class="title">班次类型：</span>
                <div data-key="type" data-type="list" class="search-key list" >
                    <ul>
                        <li><span data-value="1">固定班次</span></li>
                        <li><span data-value="2">流水班次</span></li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="row" style="width: 330px">
            <div class="box">
                <span class="title">订单状态：</span>
                <div  data-key="order_status" data-type="select" class="txt search-key" >
                    <select name="order_status" lay-filter="order_status" class="select">
                        <option value="">请选择</option>
                        <option value="0">未支付</option>
                        <option value="1">未派车</option>
                        <option value="2">已派车</option>
                        <option value="3">已发车</option>
                        <option value="4">已完成</option>
                        <option value="5">已失效</option>
                    </select>
                </div>
            </div>
        </div>
    </div>
    <div class="item">
        <div class="row" style="width: 500px">
            <div class="box">
                <span class="title">变更状态：</span>
                <div  data-key="status" data-type="select" class="txt search-key" >
                    <select name="status" lay-filter="status" class="select" style="width: 190px;">
                        <option value="">请选择</option>
                        <option value="0">取消</option>
                        <option value="1">未支付过期</option>
                        <option value="3">改签</option>
                        <option value="4">退款</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row" style="width: 330px">
            <div class="box">
                <span class="title">发车时间：</span>
                <div class="txt">
                    <span data-key="departuretime" data-type="txt" class="search-key"><input type="text" id="date2" readonly style="width: 250px;" placeholder=""/></span>
                </div>
            </div>
        </div>
    </div>
    <div class="item">
        <div class="row" style="width: 500px">
            <div class="box">
                <span class="title">车牌号：</span>
                <div  data-key="plate" data-type="select" class="txt search-key" >
                    <select name="plate" lay-filter="plate" class="select" style="width: 190px;">
                        <option value="0">请选择</option>
                        <?php foreach ($carallplate as $key => $value) { ?>
                            <option value="<?php echo $value['id']; ?>"> <?php echo $value['plate']; ?> </option>
                        <?php } ?>
                    </select>
                </div>
            </div>
        </div>
        <div class="row" style="width: 430px">
            <div class="box">
                <span class="title">站点：</span>
                <div  data-key="ssite" data-type="select" class="txt search-key" style="float: left;">
                    <select name="ssite" lay-filter="ssite" class="select">
                        <option value="0">请选择</option>
                        <?php foreach ($allssite as $key => $value) { ?>
                            <option value="<?php echo $value['id']; ?>"> <?php echo $value['name']; ?> </option>
                        <?php } ?>
                    </select>
                </div>
                <div style="float: left;margin-right: 17px;">~</div>
                <div data-key="esite" data-type="select" class="txt search-key" style="float: left;">
                    <select name="esite" lay-filter="esite" class="select">
                        <option value="0">请选择</option>
                        <?php foreach ($allesite as $key => $value) { ?>
                            <option value="<?php echo $value['id']; ?>"> <?php echo $value['name']; ?> </option>
                        <?php } ?>
                    </select>
                </div>
            </div>
        </div>
    </div>
    <div class="item">
        <div class="row" style="width: 500px">
            <div class="box">
                <span class="title">线路：</span>
                <div  data-key="circuit" data-type="select" class="txt search-key" >
                    <select name="circuit" lay-filter="circuit" class="select" style="width: 190px;">
                        <option value="0">请选择</option>
                        <?php foreach ($allcircuit as $key => $value) { ?>
                            <option value="<?php echo $value['id']; ?>"> <?php echo $value['name']; ?> </option>
                        <?php } ?>
                    </select>
                </div>
            </div>
        </div>
        <div class="row" style="width: 430px">
            
        </div>
    </div>
    <div class="item">
        <div class="row" style="width: 360px;">
            <div class="box">
                <span class="title">关键字查询：</span>
                <div data-key="key" data-type="txt" class="search-key txt">
                    <input type="text" value="" placeholder="订单号/身份证/手机号/姓名"/>
                </div>
            </div>
        </div>
        <div class="row" style="width: 460px;">
            <div class="btn">
                <button class="layui-btn layui-btn-sm btn-query">查询</button>

                <?php if(Cm::$app->limitPost('/platform/order/index','sendcar')){ ?>
                    <a href="javascript:;" onclick="app.sendcar.hascheck()" class="layui-btn layui-btn-normal layui-btn-sm">派车</a>    
                <?php } ?> 
                <?php if(Cm::$app->limitPost('/platform/order/index','downexport')){ ?>
                    <a href="javascript:;" onclick="app.downexport()" class="layui-btn layui-btn-normal layui-btn-sm">导出</a>    
                <?php } ?>   
                <?php if(Cm::$app->limitPost('/platform/order/index','changecar')){ ?>
                    <a href="javascript:;" onclick="app.changecar.hascheck()" class="layui-btn layui-btn-normal layui-btn-sm">转车</a>    
                <?php } ?>   
                <?php if(Cm::$app->limitPost('/platform/order/index','poolingcar')){ ?>
                    <a href="javascript:;" onclick="app.poolingcar.hascheck()" class="layui-btn layui-btn-normal layui-btn-sm">拼车</a>    
                <?php } ?> 
                <?php if(Cm::$app->limitPost('/platform/order/index','noticesave')){ ?>
                    <a href="javascript:;" onclick="app.notice.show()" class="layui-btn layui-btn-normal layui-btn-sm">通告</a>    
                <?php } ?> 
            </div>
        </div>
    </div>
</div>
<table data-url="<?php echo $baseUrl; ?>?action=list"
       data-search="#search-box"
       data-page=""
       data-height="full-380"
       id="data-list" 
       lay-filter='data-list' style="display: none;">
    <thead>
    <tr>
        <th width="160" align="center" field="order_number">订单号</th>
        <th width="250" field="circuit_name">线路名称</th>
        <th width="160" align="center" field="departuretime">发车时间</th>
        <th width="130" align="center" templet="#tpl-order_status">订单状态</th>
        <th width="90" align="center" field="ridership">乘客数</th>
        <th width="100" align="center" field="order_price">订单金额</th>
        <th width="160" align="center" field="addtime">创建时间</th>
        <th minWidth="230" align="center" toolbar="#tpl-cmd">操作</th>
    </tr>
    </thead>
</table>

<script type="text/html" id="tpl-order_status">
    {{# if(d.order_status==0){ }}
    <span>待支付</span>
    {{# }else if(d.order_status==1){ }}
    <span class="green">待出票</span>
    {{# }else if(d.order_status==2){ }}
    <span class="green">已派车</span>
    {{# }else if(d.order_status==3){ }}
    <span class="green">已发车</span>
    {{# }else if(d.order_status==4){ }}
    <span class="blue">已完成</span>
    {{# }else if(d.order_status==5){ }}
    <span class="red">
        {{# if(d.status == 0){ }}
        已取消
        {{# }else if(d.status==1){ }}
        已过期
        {{# }else if(d.status==2){ }}
        已删除
        {{# }else if(d.status==3){ }}
        已改签
        {{# }else if(d.status==4){ }}
        已退票
        {{# } }}
    </span>
    {{# }}}
</script>

<script type="text/html" id="tpl-pay_type">
    {{# if(d.pay_type==1){ }}
    <span>微信</span>
    {{# }else{ }}
    <span>支付宝</span>
    {{# }}}
</script>

<script type="text/html" id="tpl-cmd">
    <?php if(Cm::$app->limitPost('/platform/order/index','info')){ ?>
        <a href="javascript:;" onclick="app.info(this,{{d.id}})" class="layui-btn layui-btn-normal layui-btn-sm">详情</a>
    <?php } ?>
    <?php if(Cm::$app->limitPost('/platform/order/index','changelist')){ ?>
        {{# if(d.change_list==1){ }}
        <a href="javascript:;" onclick="app.change.list(this,{{d.id}})" class="layui-btn layui-btn-normal layui-btn-sm">改签记录</a>
        {{# } }}
    <?php } ?>
    {{# if(d.status==4){ }}
    <a href="javascript:;" onclick="app.refundinfo(this,{{d.id}})" class="layui-btn layui-btn-normal layui-btn-sm">退票详情</a>
    {{# } }}

    <?php if(Cm::$app->limitPost('/platform/order/index','refund')){ ?>
        {{# if(d.status==1 && d.order_status==1){ }}
        <a href="javascript:;" onclick="app.refund({{d.id}})" class="layui-btn layui-btn-normal layui-btn-sm">退票</a>
        {{# } }}        
    <?php } ?>   
    <span style="display: none;">{{JSON.stringify(d)}}</span>
</script>
<script type="text/html" id="tpl-sendcar">
    <div class="layui-card" style="box-shadow: none;">
        <div class="layui-card-header">派车</div>
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div id="sendcar-box">
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择线路</label>
                        <div class="layui-input-inline">
                            <select lay-filter="circuit" id="circuit">
                                <option value="">请选择</option>
                                {{each circuit as value}}
                                <option value="{{value.circuit_id}}">{{value.name}}</option>
                                {{/each}}
                            </select>  
                        </div>

                        <label class="layui-form-label">选择班次</label>
                        <div class="layui-input-inline" id="shift-box">
                            <select lay-filter="shift" id="shift">
                                <option value="">请选择</option>
                            </select>  
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">车辆选择</label>
                        <div class="layui-input-inline" id="car-box">
                            <select lay-filter="car" id="car">
                                <option value="">请选择</option>
                            </select>  
                        </div>

                        <label class="layui-form-label">检票员</label>
                        <div class="layui-input-inline" id="inspector-box">
                            <select lay-filter="inspector" id="inspector">
                                <option value="">请选择</option>
                            </select>  
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">车辆座位</label>
                        <div class="layui-input-inline h38" id="carnum"></div>                              
                    </div>
                    <div class="layui-form-item">                      
                        <label class="layui-form-label">上轮发车</label>
                        <div class="layui-input-block h38" id="lasttime">无</div>                         
                    </div>
                    <div class="layui-form-item">                      
                        <label class="layui-form-label">下轮发车</label>
                        <div class="layui-input-block h38" id="nexttime">无</div>                          
                    </div>
                    <div class="layui-form-item">
                        <a href="javascript:;"  onclick="app.sendcar.select_all()" class="layui-btn layui-btn-warm layui-btn-sm">全选</a>
                    </div>
                    <div id="passenger_box" style="overflow:hidden;overflow-y: auto;margin-bottom: 10px;">
                        
                    </div>
                </div>
                <?php if(Cm::$app->limitPost('/platform/order/index','sendcar')){ ?>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="shiftsave">保存</button>
                    </div>
                </div>
                <?php } ?>
            </form>
        </div>
    </div>
</script>
<script type="text/html" id="tpl-shift">
    <select lay-filter="{{name}}" id="{{name}}">
        <option value="0">请选择</option>
        {{each shift as item}}
        <option value="{{item.shift_id}}">{{item.departuretime}}</option>
        {{/each}}
    </select>  
</script>
<script type="text/html" id="tpl-car">
    <select lay-filter="{{name}}" id="{{name}}">
        <option value="0">请选择</option>
        {{each car as item}}
        <option value="{{item.id}}" p_seat="{{item.p_seat}}" seatnum="{{item.seatnum}}">{{item.plate}}</option>
        {{/each}}
    </select>  
</script>
<script type="text/html" id="tpl-inspector">
    <select lay-filter="{{name}}" id="{{name}}">
        <option value="0">请选择</option>
        {{each inspector as item}}
        <option value="{{item.id}}">{{item.name}}</option>
        {{/each}}
    </select>  
</script>
<script type="text/html" id="tpl-circuit">
    <select lay-filter="{{name}}" id="{{name}}">
        <option value="0">请选择</option>
        {{each circuit as item}}
        <option value="{{item.circuit_id}}">{{item.name}}</option>
        {{/each}}
    </select>  
</script>
<script type="text/html" id="tpl-sendcar-order">
    <div id="sendcar-order-table">
        <table class="layui-table">
            <colgroup>
                <col width="80">
                <col width="180">
                <col width="180">
                <col width="100">
                <col >
            </colgroup>
            <thead>
                <tr>
                    <th class="center">序号</th>
                    <th class="center">订单号</th>
                    <th class="center">下单时间</th>
                    <th class="center">乘客人数</th>
                    <th class="center">
                        <input type="checkbox" name="allselect" lay-skin="primary" lay-filter="allselect">
                        是否派车</th>
                </tr> 
            </thead>
            <tbody>
                {{if list.length == 0}}
                    <tr>
                        <td class="center" colspan="5">没有查询到订单信息</td>
                    </tr>
                {{else}}
                    {{each list as item}}
                    {{if car_id!=0 && car_id==item.car_id}}
                    <tr>
                        <td class="center">{{item.ids}}</td>
                        <td class="center">{{item.order_number}}</td>
                        <td class="center">{{item.addtime}}</td>
                        <td class="center">{{item.ridershipstr}}</td>
                        <td class="center">
                            <input type="checkbox" value="{{item.order_id}}" data-ridership="{{item.ridership}}" class="sendcaradd" title="确定" lay-filter="sendcaradd">
                        </td>
                    </tr>
                    {{else if car_id==0}}
                    <tr>
                        <td class="center">{{item.ids}}</td>
                        <td class="center">{{item.order_number}}</td>
                        <td class="center">{{item.addtime}}</td>
                        <td class="center">{{item.ridershipstr}}</td>
                        <td class="center">
                            <input type="checkbox" value="{{item.order_id}}" data-ridership="{{item.ridership}}" class="sendcaradd" title="确定" lay-filter="sendcaradd">
                        </td>
                    </tr>    
                    {{/if}}
                    {{/each}}
                {{/if}}
            </tbody>
        </table>
    </div>
</script>
<script type="text/html" id="tpl-sendcar-add">
    <input type="checkbox" value="{{d.order_id}}" data-ridership="{{d.ridership}}" class="sendcaradd" title="确定" lay-filter="sendcaradd">
</script>

<script type="text/html" id="tpl-order-info">
    <div class="layui-card-body">
        <div class="layui-row">
            <label class="layui-form-label">线路名称：</label>
            <div class="layui-input-inline">
                <div class="layui-form-mid">{{item.info.circuitname}}</div>
            </div>
        </div> 
        <div class="layui-row">
            <label class="layui-form-label">城市行程：</label>
            <div class="layui-input-inline">
                <div class="layui-form-mid">{{item.info.citysname}}--{{item.info.cityename}}</div>
            </div>
        </div>    
        <div class="layui-row">
            <label class="layui-form-label">站点行程：</label>
            <div class="layui-input-inline">
                <div class="layui-form-mid">{{item.info.sitesname}}--{{item.info.siteename}}</div>
            </div>
        </div>
        <div class="layui-row">
            <label class="layui-form-label" style="width: 100px;">上下车地址：</label>
            <div class="layui-input-inline">
                <div class="layui-form-mid">{{item.info.s_address}}</div>
                <div class="layui-form-mid">{{item.info.siteename}}</div>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">班次类型：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.shifttype==1?'固定班次':'流水班次'}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6">
                <label class="layui-form-label">发车时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.departuretime}}</div>
                </div>
            </div>    
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">下单人：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.name}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">手机号：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.user_telephone}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">订单状态：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">
                        {{if item.info.order_status==0}}
                        <span>待支付</span>
                        {{else if item.info.order_status==1}}
                        <span class="green">已支付待派车</span>
                        {{else if item.info.order_status==2}}
                        <span class="green">已支付已派车</span>
                        {{else if item.info.order_status==3}}
                        <span class="green">已发车</span>
                        {{else if item.info.order_status==4}}
                        <span class="blue">已完成</span>
                        {{else}}
                        <span class="red">已失效</span>
                        {{/if}}
                    </div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">变更状态：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">
                        {{if item.info.status==0}}
                        <span class="red">已取消</span>
                        {{else if item.info.status==3}}
                        <span class="red">已改签</span>
                        {{else if item.info.status==4}}
                        <span class="red">已退款</span>
                        {{else if item.info.status==1}}
                        <span>正常</span>
                        {{else}}
                        <span class="red">已删除</span>
                        {{/if}}
                    </div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">订单号：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.order_number}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">订单总额：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.info.order_price}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">订单金额：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.info.price}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">服务总额：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.info.service_charge}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">保险总额：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.info.premium}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">下单来源：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.source==1?'微信':''}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">是否检票：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.is_check==0?'否':'是'}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">下单时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.addtime}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">更新时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.updatetime}}</div>
                </div>    
            </div>
        </div>
        <div class="layui-row {{item.info.status==0?'':'hide'}}">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">取消时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.canceltime}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row {{item.info.pay_type==0?'hide':''}}">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">支付方式：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.pay_type==1?'微信':'支付宝'}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">支付时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.pay_time}}</div>
                </div>    
            </div>
        </div>
        {{if item.car!=''}}
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">车辆信息</label>
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">车牌：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.car.plate}}</div>
                </div>    
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">检票员：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.car.name}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">手机号：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.car.telephone}}</div>
                </div>    
            </div>
        </div>
        {{/if}}
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">乘客信息</label>
            </div>
        </div> 
        {{each item.passenger as vs}}
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">姓名：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{vs.name}}(<span class="{{vs.is_check==0?'':'green'}}">{{vs.is_check==0?"未检票":"已检票"}}</span>)</div>
                </div>    
            </div>
            <div class="layui-col-xs6 {{vs.seat_number !=0 ? '':'hide'}}"> 
                <label class="layui-form-label">车位座：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{vs.seat_number}}号</div>
                </div>    
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">手机：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{vs.telephone}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">身份证：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{vs.id_card}}</div>
                </div>    
            </div>
        </div>
        {{/each}}
    </div>
</script>
<script type="text/html" id="tpl-order-refundinfo">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label" style="width: 100px;">退款单单号：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.refund_number}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">退款金额：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.refund_amount}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">手续费：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.refund_service}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">退款状态：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.refund_status==0?'退款中':(item.refund_status==1?'退款成功':'退款失败')}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">退款时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.refund_time}}</div>
                </div>    
            </div>
        </div>
    </div>
</script>
<script type="text/html" id="tpl-audit-list">
    {{each item as vs is}}
    <div class="layui-row">
        <label class="layui-form-label" style="width: 100px;">旧线路名称：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{vs.oldcircuitname}}</div>
        </div>
    </div> 
    <div class="layui-row">
        <label class="layui-form-label" style="width: 100px;">旧发车时间：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{vs.olddeparturetime}}</div>
        </div>
    </div>    
    <div class="layui-row">
        <label class="layui-form-label" style="width: 100px;">新线路名称：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{vs.newcircuitname}}</div>
        </div>
    </div>
    <div class="layui-row">
        <label class="layui-form-label" style="width: 100px;">新发车时间：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{vs.newdeparturetime}}</div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs6"> 
            <label class="layui-form-label" style="width: 100px;">改签时间：</label>
            <div class="layui-input-inline">
                <div class="layui-form-mid">{{vs.addtime}}</div>
            </div>
        </div>
    </div>
    {{if vs.auditnumber}}
    <div class="layui-row">
        <label class="layui-form-label" style="width: 100px;">改签后新订单：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{vs.auditnumber}}</div>
        </div>
    </div>
    {{/if}}
    {{if is!=0}}
    <div class="xian"></div>
    {{/if}}
    {{/each}}
</script>

<script type="text/html" id="tpl-changecar">
    <div class="layui-card" style="box-shadow: none;">
        <div class="layui-card-header">转车</div>
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div id="changecar-box">
                    <div class="layui-form-item">
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">订单类型</label>
                            <div class="layui-input-inline">
                                <select lay-filter="ordertype" id="ordertype">
                                    <option value="0">请选择</option>
                                    <option value="1">未派车</option>
                                    <option value="2">已派车</option>
                                </select>  
                            </div>
                        </div>    
                    </div>        
                    <div class="layui-form-item">
                        <div class="layui-col-xs4">    
                            <label class="layui-form-label">选择线路</label>
                            <div class="layui-input-inline" id="circuit-box">
                                <select lay-filter="circuit" id="circuit">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">选择班次</label>
                            <div class="layui-input-inline" id="shift-box">
                                <select lay-filter="shift" id="shift">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                        <div class="layui-col-xs4 hide" id="car-box-box">
                            <label class="layui-form-label">选择车辆</label>
                            <div class="layui-input-inline" id="car-box">
                                <select lay-filter="car" id="car">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                    </div>        
                    <div class="layui-form-item">
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">转车线路</label>
                            <div class="layui-input-inline" id="carpool-circuit-box">
                                <select lay-filter="carpool_circuit" id="carpool_circuit">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">转车班次</label>
                            <div class="layui-input-inline" id="carpool-shift-box">
                                <select lay-filter="carpool_shift" id="carpool_shift">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">转车车辆</label>
                            <div class="layui-input-inline" id="carpool-car-box">
                                <select lay-filter="carpool_car" id="carpool_car">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">车辆座位</label>
                        <div class="layui-input-inline h38" id="carnum"></div>                              
                    </div>
                    <div id="passenger_box" style="overflow:hidden;overflow-y: auto;margin-bottom: 10px;">
                        
                    </div>
                </div>
                <?php if(Cm::$app->limitPost('/platform/order/index','sendcar')){ ?>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="carpoolsave">保存</button>
                    </div>
                </div>
                <?php } ?>
            </form>
        </div>
    </div>
</script>

<script type="text/html" id="tpl-poolingcar">
    <div class="layui-card" style="box-shadow: none;">
        <div class="layui-card-header">拼车</div>
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div id="poolingcar-box">
                    <div class="layui-form-item">
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">订单类型</label>
                            <div class="layui-input-inline">
                                <select lay-filter="ordertype" id="ordertype">
                                    <option value="0">请选择</option>
                                    <option value="1">未派车</option>
                                    <option value="2">已派车</option>
                                </select>  
                            </div>
                        </div>    
                    </div>        
                    <div class="layui-form-item">
                        <div class="layui-col-xs4">    
                            <label class="layui-form-label">选择线路</label>
                            <div class="layui-input-inline" id="circuit-box">
                                <select lay-filter="circuit" id="circuit">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">选择班次</label>
                            <div class="layui-input-inline" id="shift-box">
                                <select lay-filter="shift" id="shift">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                        <div class="layui-col-xs4 hide" id="car-box-box">
                            <label class="layui-form-label">选择车辆</label>
                            <div class="layui-input-inline" id="car-box">
                                <select lay-filter="car" id="car">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                    </div>        
                    <div class="layui-form-item">
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">拼车线路</label>
                            <div class="layui-input-inline" id="carpool-circuit-box">
                                <select lay-filter="carpool_circuit" id="carpool_circuit">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">拼车班次</label>
                            <div class="layui-input-inline" id="carpool-shift-box">
                                <select lay-filter="carpool_shift" id="carpool_shift">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">拼车车辆</label>
                            <div class="layui-input-inline" id="carpool-car-box">
                                <select lay-filter="carpool_car" id="carpool_car">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">车辆座位</label>
                        <div class="layui-input-inline h38" id="carnum"></div>                              
                    </div>
                    <div id="passenger_box" style="overflow:hidden;overflow-y: auto;margin-bottom: 10px;">
                        
                    </div>
                </div>
                <?php if(Cm::$app->limitPost('/platform/order/index','sendcar')){ ?>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="carpoolsave">保存</button>
                    </div>
                </div>
                <?php } ?>
            </form>
        </div>
    </div>
</script>

<script type="text/html" id="tpl-notice">
    <div class="layui-card" style="box-shadow: none;">
        <div class="layui-card-header">通告</div>
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div id="notice-box">
                    <div class="layui-form-item">
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">线路</label>
                            <div class="layui-input-inline">
                                <select lay-filter="circuit" id="circuit">
                                    <option value="0">请选择</option>
                                    {{each circuit as item}}
                                    <option value="{{item.circuit_id}}">{{item.name}}</option>
                                    {{/each}}
                                </select>  
                            </div>
                        </div>  
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">班次</label>
                            <div class="layui-input-inline">
                                <select lay-filter="shift" id="shift-box">
                                    <option value="0">请选择</option>
                                </select>  
                            </div>
                        </div>
                    </div>        
                    <div class="layui-form-item">
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">发送类型</label>
                            <div class="layui-input-inline">
                                <select lay-filter="isall" id="isall">
                                    <option value="0">请选择</option>
                                    <option value="1">全部订单</option>
                                    <option value="2">只发送未发送订单</option>
                                </select>  
                            </div>
                        </div> 
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">上车地址</label>
                            <div class="layui-input-block">
                                <input type="text" name="address" lay-verify="required"  value="" autocomplete="off" placeholder="请输入上车地址" class="layui-input">
                            </div>
                        </div>  
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">车牌</label>
                            <div class="layui-input-block">
                                <input type="text" name="plate" lay-verify="required"  value="" autocomplete="off" placeholder="请输入车牌号,多个用“、”隔开" class="layui-input">
                            </div>
                        </div>
                    </div>  
                    <div class="layui-form-item">
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">联系人</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" lay-verify="required"  value="" autocomplete="off" placeholder="请输入联系人" class="layui-input">
                            </div>
                        </div>  
                        <div class="layui-col-xs4">
                            <label class="layui-form-label">联系电话</label>
                            <div class="layui-input-block">
                                <input type="text" name="telephone" lay-verify="required"  value="" autocomplete="off" placeholder="请输入联系电话" class="layui-input">
                            </div>
                        </div>
                    </div>    
                    <div id="order-box" style="overflow:hidden;overflow-y: auto;margin-bottom: 10px;">
                        
                    </div>  
                </div>
                <?php if(Cm::$app->limitPost('/platform/order/index','noticesave')){ ?>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="noticesave">保存</button>
                    </div>
                </div>
                <?php } ?>
            </form>
        </div>
    </div>
</script>

<script type="text/html" id="tpl-notice-order">
    <div id="sendcar-order-table">
        <table class="layui-table">
            <colgroup>
                <col width="80">
                <col width="180">
                <col width="180">
                <col width="100">
                <col >
            </colgroup>
            <thead>
                <tr>
                    <th class="center">订单号</th>
                    <th class="center">乘客人数</th>
                    <th class="center">是否已通知</th>
                    <th class="center">上车地址</th>
                    <th class="center">车牌</th>
                    <th class="center">通知发送时间</th>
                </tr> 
            </thead>
            <tbody>
                {{if list.length == 0}}
                    <tr>
                        <td class="center" colspan="6">没有查询到订单信息</td>
                    </tr>
                {{else}}
                    {{each list as item}}
                    <tr>
                        <td class="center">{{item.order_number}}</td>
                        <td class="center">{{item.ridership}}人</td>
                        <td class="center">
                            {{if item.isnotice==1}}
                            <span style="color: green;">是</span>
                            {{else}}<span>否</span>
                            {{/if}}
                        </td>
                        <td class="center">{{item.address}}</td>
                        <td class="center">{{item.plate}}</td>
                        <td class="center">{{item.addtime}}</td>
                    </tr>
                    {{/each}}
                {{/if}}
            </tbody>
        </table>
    </div>
</script>
<script>
    var select_all_i=0;
    var app = {
        init:function(){
            $('#data-list').table();
            app.form.init();
            var laydate = layui.laydate;
            laydate.render({
                elem: '#date2'
                ,type: 'datetime'
                ,range: '至' 
                ,done:function () {
                    setTimeout(function () {
                        $('#data-list').table();
                    },200)
                }
            });
        },
        form: {
            obj: null,
            init: function () {
                var form = layui.form;
                form.render();
                this.obj = form;
            },
            render: function () {
                this.obj.render();
            }
        },
        info:function(e,id){
            $.post(baseUrl+'&action=info',{id:id},function (d) {
                if(d.flag)
                {
                    layer.open({
                        title:'订单详情',
                        area:['600px','60%'],
                        type:1,
                        shadeClose:true,
                        content:template('tpl-order-info', {item:d.data})
                    });
                }else{
                    layer.msg(d.msg);
                }
            },'json')
        },
        refundinfo:function(e,id){
            var str=$(e).parent().find('span').html();
            var json=eval('('+str+')');
            layer.open({
                title:'退票详情',
                area:['600px','300px'],
                type:1,
                shadeClose:true,
                content:template('tpl-order-refundinfo', {item:json})
            });
        },
        change:{
            list:function(e,id){
                $.post(baseUrl+'&action=changelist',{id:id},function (d) {
                    if(d.flag)
                    {
                        layer.open({
                            title:'改签记录',
                            area:['600px','60%'],
                            type:1,
                            shadeClose:true,
                            content:template('tpl-audit-list', {item:d.data})
                        });       
                    }else{
                        layer.msg(d.msg);
                    }
                },'json')
            }
        },
        sendcar:{
            circuit:[],
            data:{
                circuit_id:0,
                shift_id:0,
                inspector_id:0,
                car_id:0,
                cartotal:0,
                passengernum:0,
                passenger:[],
                order:[]
            },
            carlist:[],
            orderlist:[],
            hascheck:function(){
                $.post(baseUrl+'&action=sendcar',{ischeck:1},function (d) {
                    if(d.flag){
                        app.sendcar.circuit = d.data;
                        layer.open({
                            title:false,
                            area:['90%','80%'],
                            type:1,
                            content:template('tpl-sendcar', {circuit:d.data}),
                            success: function(layero, index){
                                var height = $("#layui-layer" + index).height() - 120;
                                $("#layui-layer" + index +" form #sendcar-box").css("height",height+"px");
                                var pheight = height-280;
                                $("#layui-layer" + index +" form #sendcar-box #passenger_box").css("height",pheight+"px")
                                app.form.obj.on('select(circuit)',function(data){
                                    app.sendcar.data.circuit_id = data.value;
                                    app.sendcar.data.shift_id = 0;
                                    var shift = [];
                                    if(data.value != 0){
                                        shift = app.sendcar.circuit[data.value].shift;
                                    }
                                    $("#shift-box").html(template('tpl-shift',{shift:shift,name:'shift'}));
                                    app.sendcar.order();
                                    app.form.obj.render();
                                });
                                app.form.obj.on('select(shift)',function(data){
                                    app.sendcar.data.shift_id = data.value;
                                    app.sendcar.order();
                                    app.form.obj.render();
                                });
                                app.form.obj.on('select(inspector)',function(data){
                                    app.sendcar.data.inspector_id = data.value;
                                    app.form.obj.render();
                                });
                                app.form.obj.on('select(car)',function(data){
                                    if(data.value != app.sendcar.data.car_id){
                                        $(".sendcaradd").prop("checked", false);
                                        app.sendcar.data.car_id = data.value;
                                        var p_seat = 0;
                                        var seatnum = 0;
                                        var lasttime = '无';
                                        var nexttime = '无';
                                        $.each(app.sendcar.carlist,function(r,val){
                                            if(data.value == val.id){
                                                p_seat = val.p_seat;
                                                seatnum = val.seatnum;
                                                lasttime = val.lasttime;
                                                nexttime = val.nexttime;
                                            }    
                                        });
                                        app.sendcar.data.cartotal = p_seat;
                                        app.sendcar.data.passengernum = seatnum;
                                        app.sendcar.data.passenger = [];
                                        app.sendcar.data.order = [];
                                        $("#carnum").html(seatnum+"/"+p_seat);
                                        $("#lasttime").html(lasttime);
                                        $("#nexttime").html(nexttime);
                                        app.form.obj.render();
                                    }
                                });
                                app.form.obj.on("submit(shiftsave)",function(data){
                                    if(app.sendcar.data.circuit_id == 0){
                                        layer.msg("请选择派车的路线", {icon: 5});
                                        return false;
                                    }
                                    if(app.sendcar.data.shift_id == 0){
                                        layer.msg("请选择派车的班次", {icon: 5});
                                        return false;
                                    }
                                    if(app.sendcar.data.car_id == 0){
                                        layer.msg("请选择派车的车辆", {icon: 5});
                                        return false;
                                    }
                                    if(app.sendcar.data.inspector_id == 0){
                                        layer.msg("请选择派车的检票员", {icon: 5});
                                        return false;
                                    }
                                    if(app.sendcar.data.order.length == 0){
                                        layer.msg("请选择派车的订单", {icon: 5});
                                        return false;    
                                    }
                                    if(app.sendcar.data.passenger.length == 0){
                                        layer.msg("请选择派车的订单", {icon: 5});
                                        return false;    
                                    }
                                    app.sendcar.data.passenger = JSON.stringify(app.sendcar.data.passenger);
                                    app.sendcar.data.order = JSON.stringify(app.sendcar.data.order);
                                    app.sendcar.save();
                                    return false;
                                });
                                app.sendcar.order();
                                app.form.obj.render();
                            }
                        });
                        
                    }else{
                        layer.msg(d.msg);
                    }
                },'json');
            },
            order:function(){
                app.sendcar.data.inspector_id=0;
                app.sendcar.data.car_id=0;
                app.sendcar.data.cartotal=0;
                app.sendcar.data.passengernum=0;
                app.sendcar.data.passenger=[];
                app.sendcar.data.order=[];
                var pdata = {
                    shift_id:app.sendcar.data.shift_id,
                    isorderlist:1
                }
                $("#carnum").html("0/0");
                $("#lasttime").html("无");
                $("#nexttime").html("无");
                if(pdata.shift_id == 0){
                    $("#car-box").html(template('tpl-car',{car:[],name:'car'}));
                    app.sendcar.carlist = [];
                    app.sendcar.orderlist = [];
                    $("#inspector-box").html(template('tpl-inspector',{inspector:[],name:'inspector'}));
                    app.form.obj.render();
                    app.sendcar.passengertable();
                    return false;
                }
                $.post(baseUrl+'&action=sendcar',pdata,function (d) {
                    var list = []
                    var car = [];
                    var inspector = [];
                    if(d.flag){
                        list = d.data.list;
                        car = d.data.car;
                        inspector = d.data.inspector;
                    }
                    $("#car-box").html(template('tpl-car',{car:car,name:'car'}));
                    app.sendcar.carlist = car;
                    app.sendcar.orderlist = list;
                    $("#inspector-box").html(template('tpl-inspector',{inspector:inspector,name:'inspector'}));
                    app.form.obj.render();
                    app.sendcar.passengertable();
                },'json');
            },
            passengertable:function(){
                $("#passenger_box").html(template('tpl-sendcar-order',{list:app.sendcar.orderlist,car_id:0}));
                app.form.obj.render();
                app.form.obj.on('checkbox(sendcaradd)', function(obj){
                    var order_id = obj.value;
                    var ridership = $(this).attr("data-ridership");
                    var isadd = true;
                    var passengernum = app.sendcar.data.passengernum;
                    var cartotal = app.sendcar.data.cartotal;
                    var status = obj.elem.checked ? false : true;
                    if(cartotal == 0){
                        layer.msg("请选择车辆", {icon: 5});
                        isadd = false;
                    }
                    if(cartotal == passengernum && isadd && !status){
                        layer.msg("该车辆的乘客人数已满无法在添加乘客", {icon: 5});
                        isadd = false;    
                    }
                    if(!isadd){
                        obj.elem.checked = status;
                        app.form.obj.render();
                        return false;
                    }
                    var passenger = [];
                    $.each(app.sendcar.orderlist,function(ks,vs){
                        if(vs.order_id == order_id){
                            passenger = vs.passenger;
                        }
                    });
                    if(obj.elem.checked){
                        passengernum = parseInt(passengernum) + passenger.length;
                        if(passengernum > cartotal){
                            layer.msg("已超出该车辆的乘客人数,请选择其它订单！", {icon: 5});
                            obj.elem.checked = status;
                            app.form.obj.render();
                            return false;       
                        }
                        $.each(passenger,function(r,val){
                            app.sendcar.data.passenger.push(val.passenger_id);    
                        });
                        app.sendcar.data.order.push(order_id);
                    }else{
                        passengernum = parseInt(passengernum) - passenger.length;
                        if(passengernum <= 0){
                            passengernum = 0;
                            app.sendcar.data.passenger = [];
                            app.sendcar.data.order = [];
                        }else{
                            $.each(passenger,function(r,val){
                                $.each(app.sendcar.data.passenger,function(k,v){
                                    if(v==val.passenger_id){
                                        app.sendcar.data.passenger.splice(k,1);
                                    }
                                })
                            });
                            $.each(app.sendcar.data.order,function(r,val){
                                if(val == order_id){
                                    app.sendcar.data.order.splice(r,1);
                                }
                            })
                        }    
                    }
                    app.sendcar.data.passengernum = passengernum;
                    $("#carnum").html(passengernum+"/"+cartotal);
                });
            },
            save:function(){
                $.post(baseUrl+'&action=save',app.sendcar.data,function (d) {
                    if(d.flag){
                        layer.closeAll();
                        $('#data-list').table(); 
                        layer.msg("保存成功");
                    }else{
                        layer.msg(d.msg, {icon: 5});
                        app.sendcar.data.passenger = JSON.parse(app.sendcar.data.passenger);
                        app.sendcar.data.order = JSON.parse(app.sendcar.data.order);
                        setTimeout(function () {
                            layer.closeAll();
                            $('#data-list').table();
                        },2000)

                        return false;
                    }
                },'json');        
            },
            select_all:function (){
                select_all_i++;
                var checkboxes = $(".sendcaradd");
                var checkedId = [];
                var passengernum_check=0;
                if(select_all_i%2!=0){
                    checkboxes.prop("checked",true);
                    checkboxes.each(function(k, v){
                        if ($(v).is(':checked')) {
                            checkedId.push($(v).val())
                        }
                        $.each(app.sendcar.orderlist,function(ks,vs){
                            if(vs.order_id == $(v).val()){
                                passengernum_check+=vs.passenger.length;
                                $.each(vs.passenger,function(r,val){
                                    app.sendcar.data.passenger.push(val.passenger_id);
                                });
                            }
                        });
                    })
                    app.sendcar.data.order=checkedId;
                    if(passengernum_check > app.sendcar.data.cartotal){
                        layer.msg("已超出该车辆的乘客人数,请选择其它订单！", {icon: 5});
                        app.form.obj.render();
                        return false;
                    }
                    app.sendcar.data.passengernum=passengernum_check;
                }else{
                    checkboxes.prop("checked",false);
                    checkedId = [];
                    app.sendcar.data.order=checkedId;
                    app.sendcar.data.passengernum=0;
                    app.sendcar.data.passenger=[];
                }
                app.form.obj.render();
            }
        },
        downexport:function(){
            var url="<?php echo \yii\helpers\Url::to(['/platform/order/downexport','1'=>1]) ?>";

            var where = $('#data-list').data('where');

            for(var k in where){
                url+="&"+k+"="+where[k];
            }
            location.href = url;
        },
        changecar:{
            circuit:[],
            ordertype:0,
            data:{
                circuit_id:0,
                shift_id:0,
                car_id:0,
                cartotal:0,
                passengernum:0,
                passenger:[],
                order:[],
                carpool_circuit:0,
                carpool_shift:0,
                carpool_car:0,
                carpool_inspector:0,
                type:'change'
            },
            carlist:[],
            orderlist:[],
            carpoollist:[],
            carpoolshift:[],
            carpoolcar:[],
            hascheck:function(){
                layer.open({
                    title:false,
                    area:['90%','80%'],
                    type:1,
                    content:template('tpl-changecar', {}),
                    success: function(layero, index){
                        var height = $("#layui-layer" + index).height() - 120;
                        $("#layui-layer" + index +" form #changecar-box").css("height",height+"px");
                        var pheight = height-240;
                        $("#layui-layer" + index +" form #changecar-box #passenger_box").css("height",pheight+"px");
                        app.changecar.checkcircuit();
                    }            
                });
                app.form.obj.render();
                app.form.obj.on('select(ordertype)',function(data){
                    app.changecar.ordertype = data.value;
                    app.changecar.checkcircuit();
                    app.form.obj.render();
                });
                app.form.obj.on('select(circuit)',function(data){
                    app.changecar.data.circuit_id = data.value;
                    app.changecar.data.shift_id = 0;
                    var shift = [];
                    if(data.value != 0){
                        shift = app.changecar.circuit[data.value].shift;
                    }
                    $("#shift-box").html(template('tpl-shift',{shift:shift,name:'shift'}));
                    app.changecar.order();
                    app.form.obj.render();
                });
                app.form.obj.on('select(shift)',function(data){
                    app.changecar.data.shift_id = data.value;
                    app.changecar.order();
                    app.form.obj.render();
                });
                app.form.obj.on('select(car)',function(data){
                    app.changecar.data.car_id = data.value;
                    app.changecar.passengertable(app.changecar.orderlist,data.value);
                    app.form.obj.render();
                });
                app.form.obj.on('select(carpool_circuit)',function(data){
                    app.changecar.initcarpool();
                    app.changecar.data.carpool_circuit = data.value;
                    app.changecar.carpoolshift = data.value == 0 ? [] : app.changecar.carpoollist[data.value].list;
                    app.changecar.carpoolcar = [];
                    $("#carpool-shift-box").html(template('tpl-shift',{shift:app.changecar.carpoolshift,name:'carpool_shift'}));
                    $("#carpool-car-box").html(template('tpl-car',{car:app.changecar.carpoolcar,name:'carpool_car'}));
                    app.form.obj.render();
                });
                app.form.obj.on('select(carpool_shift)',function(data){
                    var carpool_circuit = app.changecar.data.carpool_circuit;
                    app.changecar.initcarpool();
                    app.changecar.data.carpool_shift = data.value;
                    app.changecar.data.carpool_circuit = carpool_circuit;
                    app.changecar.carpoolcar = data.value == 0 ? [] : app.changecar.carpoolshift[data.value].list;
                    $("#carpool-car-box").html(template('tpl-car',{car:app.changecar.carpoolcar,name:'carpool_car'}));
                    app.form.obj.render();
                });
                app.form.obj.on('select(carpool_car)',function(data){
                    var carpool_shift = app.changecar.data.carpool_shift;
                    var carpool_circuit = app.changecar.data.carpool_circuit;
                    app.changecar.initcarpool();
                    app.changecar.data.carpool_circuit = carpool_circuit;
                    app.changecar.data.carpool_shift = carpool_shift;
                    app.changecar.data.carpool_car = data.value;
                    car = data.value == 0 ? [] : app.changecar.carpoolcar[data.value];
                    $(".sendcaradd").prop("checked", false);
                    if(data.value != 0){
                        app.changecar.data.cartotal=car.p_seat;
                        app.changecar.data.passengernum=car.seatnum;
                        app.changecar.data.carpool_inspector = car.inspector;
                        $("#carnum").html(car.seatnum+"/"+car.p_seat);
                    }else{
                        $("#carnum").html("0/0");   
                    }
                    app.form.obj.render();
                });
                app.form.obj.on("submit(carpoolsave)",function(data){
                    if(app.changecar.data.circuit_id == 0){
                        layer.msg("请选择路线", {icon: 5});
                        return false;
                    }
                    if(app.changecar.data.shift_id == 0){
                        layer.msg("请选择班次", {icon: 5});
                        return false;
                    }
                    if(app.changecar.data.carpool_circuit == 0){
                        layer.msg("请选择转车的路线", {icon: 5});
                        return false;
                    }
                    if(app.changecar.data.carpool_shift == 0){
                        layer.msg("请选择转车的班次", {icon: 5});
                        return false;
                    }
                    if(app.changecar.data.carpool_car == 0){
                        layer.msg("请选择转车的车辆", {icon: 5});
                        return false;
                    }
                    if(app.changecar.data.carpool_inspector == 0){
                        layer.msg("请选择转车的车辆", {icon: 5});
                        return false;
                    }
                    if(app.changecar.data.order.length == 0){
                        layer.msg("请选择转车的订单", {icon: 5});
                        return false;    
                    }
                    if(app.changecar.data.passenger.length == 0){
                        layer.msg("请选择转车的订单", {icon: 5});
                        return false;    
                    }
                    app.changecar.data.passenger = JSON.stringify(app.changecar.data.passenger);
                    app.changecar.data.order = JSON.stringify(app.changecar.data.order);
                    app.changecar.save();
                    return false;
                });
            },
            checkcircuit:function(){
                $("#car-box-box").hide();
                app.changecar.data.car_id = 0;
                if(app.changecar.ordertype == 0){
                    $("#circuit-box").html(template('tpl-circuit',{circuit:[],name:'circuit'}));
                    app.changecar.circuit = [];
                }else{
                    $.post(baseUrl+'&action=changecar',{isordertype:app.changecar.ordertype,isorderlist:0},function (d) {
                        if(d.flag){
                            app.changecar.circuit = d.data;
                            $("#circuit-box").html(template('tpl-circuit',{circuit:d.data,name:'circuit'}));
                            if(app.changecar.ordertype == 2){
                                $("#car-box-box").show();
                            }
                            app.form.obj.render();
                        }else{
                            layer.msg(d.msg);
                        }
                    },'json');
                }
                app.changecar.data.circuit_id = 0;
                app.changecar.data.shift_id = 0;
                $("#shift-box").html(template('tpl-shift',{shift:[],name:'shift'}));
                app.changecar.order();
                app.form.obj.render();
            },
            initcarpool:function(){
                app.changecar.data.cartotal=0;
                app.changecar.data.passengernum=0;
                app.changecar.data.passenger=[];
                app.changecar.data.order=[];
                app.changecar.data.carpool_circuit = 0;
                app.changecar.data.carpool_shift = 0;
                app.changecar.data.carpool_car = 0;
                app.changecar.data.carpool_inspector=0;
                if(app.changecar.ordertype == 1){
                    app.changecar.data.car_id = 0;    
                }
                
            },
            order:function(){
                app.changecar.initcarpool();
                var pdata = {
                    isordertype:app.changecar.ordertype,
                    shift_id:app.changecar.data.shift_id,
                    isorderlist:1
                }
                $("#carnum").html("0/0");
                var list = [];
                var carpool = [];
                if(pdata.shift_id == 0){
                    app.changecar.passengertable(list);
                    app.changecar.changecarpool(carpool);
                    if(app.changecar.ordertype == 2){
                        app.changecar.carlist = [];
                        $("#car-box").html(template('tpl-car',{car:[],name:'car'}));
                    }    
                    return false;
                }
                $.post(baseUrl+'&action=changecar',pdata,function (d) {
                    var car = [];
                    if(d.flag){
                        list = d.data.list;
                        carpool = d.data.carpool;
                        car = d.data.car;
                    }
                    if(app.changecar.ordertype == 2){
                        $("#car-box").html(template('tpl-car',{car:car,name:'car'}));
                    }
                    app.changecar.passengertable(list);
                    app.changecar.changecarpool(carpool);
                },'json');
            },
            passengertable:function(list,car_id=0){
                app.changecar.orderlist = list;
                $("#passenger_box").html(template('tpl-sendcar-order',{list:list,car_id:car_id}));
                app.form.obj.on('checkbox(allselect)', function(obj){
                    var status = obj.elem.checked; // 获取全选复选框的选中状态
                    var cartotal = app.changecar.data.cartotal;
                    var passengernum = app.changecar.data.passengernum;
                    var transformedData = list.reduce((accumulator, currentItem) => {
                        // 确保passenger数组非空且有id属性
                        accumulator[currentItem.order_id] = currentItem.passenger;
                        return accumulator;
                    }, {});
                    if(status){
                        if(app.changecar.ordertype == 2 && app.changecar.data.car_id == 0){
                            layer.msg("请选择车辆", {icon: 5});
                            obj.elem.checked = false;
                            app.form.obj.render();
                            return false;
                        }
                        if(cartotal == 0 ){
                            layer.msg("请选择转车车辆", {icon: 5});
                            obj.elem.checked = false;
                            app.form.obj.render();
                            return false;
                        }
                        if(cartotal == passengernum){
                            layer.msg("该车辆的乘客人数已满无法在添加乘客", {icon: 5});
                            obj.elem.checked = false;
                            app.form.obj.render();
                            return false;
                        }
                        var passengernum = list.reduce((accumulator, currentItem) => {
                            return accumulator + currentItem.passenger.length;
                        }, 0);
                        if(passengernum > cartotal){
                            layer.msg("已超出该车辆的乘客人数,请选择其它订单！", {icon: 5});
                            obj.elem.checked = false;
                            app.form.obj.render();
                            return false;
                        }
                    }else{
                        app.changecar.data.passenger = [];
                        app.changecar.data.order = [];
                    }
                    $('tbody input[type="checkbox"]').each(function (index, item) {
                        item.checked = status;
                        if(status){
                            $.each(transformedData[$(this).val()],function(r,val){
                                app.changecar.data.passenger.push(val.passenger_id);
                            });
                            app.changecar.data.order.push($(this).val());
                        }
                    });
                    app.form.obj.render(); // 更新复选框的显示
                });
                app.form.obj.render();
                app.form.obj.on('checkbox(sendcaradd)', function(obj){
                    var order_id = obj.value;
                    var ridership = $(this).attr("data-ridership");
                    var isadd = true;
                    var passengernum = app.changecar.data.passengernum;
                    var cartotal = app.changecar.data.cartotal;
                    var status = obj.elem.checked ? false : true;
                    if(app.changecar.ordertype == 2 && app.changecar.data.car_id == 0){
                        layer.msg("请选择车辆", {icon: 5});
                        isadd = false;
                    }
                    if(cartotal == 0 && isadd && !status){
                        layer.msg("请选择转车车辆", {icon: 5});
                        isadd = false;
                    }
                    if(cartotal == passengernum && isadd && !status){
                        layer.msg("该车辆的乘客人数已满无法在添加乘客", {icon: 5});
                        isadd = false;    
                    }
                    if(!isadd){
                        obj.elem.checked = status;
                        app.form.obj.render();
                        return false;
                    }
                    var passenger = [];
                    $.each(app.changecar.orderlist,function(ks,vs){
                        if(vs.order_id == order_id){
                            passenger = vs.passenger;
                        }
                    });
                    if(obj.elem.checked){
                        passengernum = parseInt(passengernum) + passenger.length;
                        if(passengernum > cartotal){
                            layer.msg("已超出该车辆的乘客人数,请选择其它订单！", {icon: 5});
                            obj.elem.checked = status;
                            app.form.obj.render();
                            return false;       
                        }
                        $.each(passenger,function(r,val){
                            app.changecar.data.passenger.push(val.passenger_id);    
                        });
                        app.changecar.data.order.push(order_id);
                    }else{
                        passengernum = parseInt(passengernum) - passenger.length;
                        if(passengernum <= 0){
                            passengernum = 0;
                            app.changecar.data.passenger = [];
                            app.changecar.data.order = [];
                        }else{
                            $.each(passenger,function(r,val){
                                $.each(app.changecar.data.passenger,function(k,v){
                                    if(v==val.passenger_id){
                                        app.changecar.data.passenger.splice(k,1);
                                    }
                                })
                            });
                            $.each(app.changecar.data.order,function(r,val){
                                if(val == order_id){
                                    app.changecar.data.order.splice(r,1);
                                }
                            })
                        }    
                    }
                    app.changecar.data.passengernum = passengernum;
                    $("#carnum").html(passengernum+"/"+cartotal);
                });
            },
            changecarpool:function(list){
                app.changecar.carpoollist = list;
                $("#carpool-circuit-box").html(template('tpl-circuit',{circuit:list,name:'carpool_circuit'}));
                $("#carpool-shift-box").html(template('tpl-shift',{shift:[],name:'carpool_shift'}));
                $("#carpool-car-box").html(template('tpl-car',{car:[],name:'carpool_car'}));
                app.form.obj.render();
                if(list.length==0 && app.changecar.data.shift_id!=0){
                    layer.msg("没有找到适合的线路班次的车辆");
                    return false;
                }
            },
            save:function(){
                 $.post(baseUrl+'&action=carpoolsave',app.changecar.data,function (d) {
                    if(d.flag){
                        layer.closeAll();
                        $('#data-list').table(); 
                        layer.msg("保存成功");
                    }else{
                        layer.msg(d.msg, {icon: 5});
                        app.changecar.data.passenger = JSON.parse(app.changecar.data.passenger);
                        app.changecar.data.order = JSON.parse(app.changecar.data.order);
                        return false;
                    }
                },'json');
            }
        },
        poolingcar:{
            circuit:[],
            ordertype:0,
            data:{
                circuit_id:0,
                shift_id:0,
                car_id:0,
                cartotal:0,
                passengernum:0,
                passenger:[],
                order:[],
                carpool_circuit:0,
                carpool_shift:0,
                carpool_car:0,
                carpool_inspector:0,
                type:'pooling'
            },
            carlist:[],
            orderlist:[],
            carpoollist:[],
            carpoolshift:[],
            carpoolcar:[],
            hascheck:function(){
                layer.open({
                    title:false,
                    area:['90%','80%'],
                    type:1,
                    content:template('tpl-poolingcar', {}),
                    success: function(layero, index){
                        var height = $("#layui-layer" + index).height() - 120;
                        $("#layui-layer" + index +" form #poolingcar-box").css("height",height+"px");
                        var pheight = height-240;
                        $("#layui-layer" + index +" form #poolingcar-box #passenger_box").css("height",pheight+"px");
                        app.poolingcar.checkcircuit();
                    }            
                });
                app.form.obj.render();
                app.form.obj.on('select(ordertype)',function(data){
                    app.poolingcar.ordertype = data.value;
                    app.poolingcar.checkcircuit();
                    app.form.obj.render();
                });
                app.form.obj.on('select(circuit)',function(data){
                    app.poolingcar.data.circuit_id = data.value;
                    app.poolingcar.data.shift_id = 0;
                    var shift = [];
                    if(data.value != 0){
                        shift = app.poolingcar.circuit[data.value].shift;
                    }
                    $("#shift-box").html(template('tpl-shift',{shift:shift,name:'shift'}));
                    app.poolingcar.order();
                    app.form.obj.render();
                });
                app.form.obj.on('select(shift)',function(data){
                    app.poolingcar.data.shift_id = data.value;
                    app.poolingcar.order();
                    app.form.obj.render();
                });
                app.form.obj.on('select(car)',function(data){
                    app.poolingcar.data.car_id = data.value;
                    app.poolingcar.passengertable(app.poolingcar.orderlist,data.value);
                    app.form.obj.render();
                });
                app.form.obj.on('select(carpool_circuit)',function(data){
                    app.poolingcar.initcarpool();
                    app.poolingcar.data.carpool_circuit = data.value;
                    app.poolingcar.carpoolshift = data.value == 0 ? [] : app.poolingcar.carpoollist[data.value].list;
                    app.poolingcar.carpoolcar = [];
                    $("#carpool-shift-box").html(template('tpl-shift',{shift:app.poolingcar.carpoolshift,name:'carpool_shift'}));
                    $("#carpool-car-box").html(template('tpl-car',{car:app.poolingcar.carpoolcar,name:'carpool_car'}));
                    app.form.obj.render();
                });
                app.form.obj.on('select(carpool_shift)',function(data){
                    var carpool_circuit = app.poolingcar.data.carpool_circuit;
                    app.poolingcar.initcarpool();
                    app.poolingcar.data.carpool_shift = data.value;
                    app.poolingcar.data.carpool_circuit = carpool_circuit;
                    app.poolingcar.carpoolcar = data.value == 0 ? [] : app.poolingcar.carpoolshift[data.value].list;
                    $("#carpool-car-box").html(template('tpl-car',{car:app.poolingcar.carpoolcar,name:'carpool_car'}));
                    app.form.obj.render();
                });
                app.form.obj.on('select(carpool_car)',function(data){
                    var carpool_shift = app.poolingcar.data.carpool_shift;
                    var carpool_circuit = app.poolingcar.data.carpool_circuit;
                    app.poolingcar.initcarpool();
                    app.poolingcar.data.carpool_circuit = carpool_circuit;
                    app.poolingcar.data.carpool_shift = carpool_shift;
                    app.poolingcar.data.carpool_car = data.value;
                    car = data.value == 0 ? [] : app.poolingcar.carpoolcar[data.value];
                    $(".sendcaradd").prop("checked", false);
                    if(data.value != 0){
                        app.poolingcar.data.cartotal=car.p_seat;
                        app.poolingcar.data.passengernum=car.seatnum;
                        app.poolingcar.data.carpool_inspector = car.inspector;
                        $("#carnum").html(car.seatnum+"/"+car.p_seat);
                    }else{
                        $("#carnum").html("0/0");   
                    }
                    app.form.obj.render();
                });
                app.form.obj.on("submit(carpoolsave)",function(data){
                    if(app.poolingcar.data.circuit_id == 0){
                        layer.msg("请选择路线", {icon: 5});
                        return false;
                    }
                    if(app.poolingcar.data.shift_id == 0){
                        layer.msg("请选择班次", {icon: 5});
                        return false;
                    }
                    if(app.poolingcar.data.carpool_circuit == 0){
                        layer.msg("请选择拼车的路线", {icon: 5});
                        return false;
                    }
                    if(app.poolingcar.data.carpool_shift == 0){
                        layer.msg("请选择拼车的班次", {icon: 5});
                        return false;
                    }
                    if(app.poolingcar.data.carpool_car == 0){
                        layer.msg("请选择拼车的车辆", {icon: 5});
                        return false;
                    }
                    if(app.poolingcar.data.carpool_inspector == 0){
                        layer.msg("请选择拼车的车辆", {icon: 5});
                        return false;
                    }
                    if(app.poolingcar.data.order.length == 0){
                        layer.msg("请选择拼车的订单", {icon: 5});
                        return false;    
                    }
                    if(app.poolingcar.data.passenger.length == 0){
                        layer.msg("请选择拼车的订单", {icon: 5});
                        return false;    
                    }
                    app.poolingcar.data.passenger = JSON.stringify(app.poolingcar.data.passenger);
                    app.poolingcar.data.order = JSON.stringify(app.poolingcar.data.order);
                    app.poolingcar.save();
                    return false;
                });
            },
            checkcircuit:function(){
                $("#car-box-box").hide();
                app.poolingcar.data.car_id = 0;
                if(app.poolingcar.ordertype == 0){
                    $("#circuit-box").html(template('tpl-circuit',{circuit:[],name:'circuit'}));
                    app.poolingcar.circuit = [];
                }else{
                    $.post(baseUrl+'&action=poolingcar',{isordertype:app.poolingcar.ordertype,isorderlist:0},function (d) {
                        if(d.flag){
                            app.poolingcar.circuit = d.data;
                            $("#circuit-box").html(template('tpl-circuit',{circuit:d.data,name:'circuit'}));
                            if(app.poolingcar.ordertype == 2){
                                $("#car-box-box").show();
                            }
                            app.form.obj.render();
                        }else{
                            layer.msg(d.msg);
                        }
                    },'json');
                }
                app.poolingcar.data.circuit_id = 0;
                app.poolingcar.data.shift_id = 0;
                $("#shift-box").html(template('tpl-shift',{shift:[],name:'shift'}));
                app.poolingcar.order();
                app.form.obj.render();
            },
            initcarpool:function(){
                app.poolingcar.data.cartotal=0;
                app.poolingcar.data.passengernum=0;
                app.poolingcar.data.passenger=[];
                app.poolingcar.data.order=[];
                app.poolingcar.data.carpool_circuit = 0;
                app.poolingcar.data.carpool_shift = 0;
                app.poolingcar.data.carpool_car = 0;
                app.poolingcar.data.carpool_inspector=0;
                
                if(app.poolingcar.ordertype == 1){
                    app.poolingcar.data.car_id = 0;    
                }
            },
            order:function(){
                app.poolingcar.initcarpool();
                var pdata = {
                    isordertype:app.poolingcar.ordertype,
                    shift_id:app.poolingcar.data.shift_id,
                    isorderlist:1
                }
                $("#carnum").html("0/0");
                var list = [];
                var carpool = [];
                if(pdata.shift_id == 0){
                    app.poolingcar.passengertable(list);
                    app.poolingcar.poolingcarpool(carpool);
                    if(app.poolingcar.ordertype == 2){
                        app.poolingcar.carlist = [];
                        $("#car-box").html(template('tpl-car',{car:[],name:'car'}));
                    }    
                    return false;
                }
                $.post(baseUrl+'&action=poolingcar',pdata,function (d) {
                    var car = [];
                    if(d.flag){
                        list = d.data.list;
                        carpool = d.data.carpool;
                        car = d.data.car;
                    }
                    if(app.poolingcar.ordertype == 2){
                        $("#car-box").html(template('tpl-car',{car:car,name:'car'}));
                    }
                    app.poolingcar.passengertable(list);
                    app.poolingcar.poolingcarpool(carpool);
                },'json');
            },
            passengertable:function(list,car_id=0){
                app.poolingcar.orderlist = list;
                $("#passenger_box").html(template('tpl-sendcar-order',{list:list,car_id:car_id}));
                app.form.obj.on('checkbox(allselect)', function(obj){
                    var status = obj.elem.checked; // 获取全选复选框的选中状态
                    var cartotal = app.changecar.data.cartotal;
                    var passengernum = app.changecar.data.passengernum;
                    var transformedData = list.reduce((accumulator, currentItem) => {
                        // 确保passenger数组非空且有id属性
                        accumulator[currentItem.order_id] = currentItem.passenger;
                        return accumulator;
                    }, {});
                    if(status){
                        if(app.changecar.ordertype == 2 && app.changecar.data.car_id == 0){
                            layer.msg("请选择车辆", {icon: 5});
                            obj.elem.checked = false;
                            app.form.obj.render();
                            return false;
                        }
                        if(cartotal == 0 ){
                            layer.msg("请选择转车车辆", {icon: 5});
                            obj.elem.checked = false;
                            app.form.obj.render();
                            return false;
                        }
                        if(cartotal == passengernum){
                            layer.msg("该车辆的乘客人数已满无法在添加乘客", {icon: 5});
                            obj.elem.checked = false;
                            app.form.obj.render();
                            return false;
                        }
                        var passengernum = list.reduce((accumulator, currentItem) => {
                            return accumulator + currentItem.passenger.length;
                        }, 0);
                        if(passengernum > cartotal){
                            layer.msg("已超出该车辆的乘客人数,请选择其它订单！", {icon: 5});
                            obj.elem.checked = false;
                            app.form.obj.render();
                            return false;
                        }
                    }else{
                        app.changecar.data.passenger = [];
                        app.changecar.data.order = [];
                    }
                    $('tbody input[type="checkbox"]').each(function (index, item) {
                        item.checked = status;
                        if(status){
                            $.each(transformedData[$(this).val()],function(r,val){
                                app.changecar.data.passenger.push(val.passenger_id);
                            });
                            app.changecar.data.order.push($(this).val());
                        }
                    });
                    app.form.obj.render(); // 更新复选框的显示
                });
                app.form.obj.render();
                app.form.obj.on('checkbox(sendcaradd)', function(obj){
                    var order_id = obj.value;
                    var ridership = $(this).attr("data-ridership");
                    var isadd = true;
                    var passengernum = app.poolingcar.data.passengernum;
                    var cartotal = app.poolingcar.data.cartotal;
                    var status = obj.elem.checked ? false : true;
                    if(app.poolingcar.ordertype == 2 && app.poolingcar.data.car_id == 0){
                        layer.msg("请选择车辆", {icon: 5});
                        isadd = false;
                    }
                    if(cartotal == 0 && isadd && !status){
                        layer.msg("请选择拼车车辆", {icon: 5});
                        isadd = false;
                    }
                    if(cartotal == passengernum && isadd && !status){
                        layer.msg("该车辆的乘客人数已满无法在添加乘客", {icon: 5});
                        isadd = false;    
                    }
                    if(!isadd){
                        obj.elem.checked = status;
                        app.form.obj.render();
                        return false;
                    }
                    var passenger = [];
                    $.each(app.poolingcar.orderlist,function(ks,vs){
                        if(vs.order_id == order_id){
                            passenger = vs.passenger;
                        }
                    });
                    if(obj.elem.checked){
                        passengernum = parseInt(passengernum) + passenger.length;
                        if(passengernum > cartotal){
                            layer.msg("已超出该车辆的乘客人数,请选择其它订单！", {icon: 5});
                            obj.elem.checked = status;
                            app.form.obj.render();
                            return false;       
                        }
                        $.each(passenger,function(r,val){
                            app.poolingcar.data.passenger.push(val.passenger_id);    
                        });
                        app.poolingcar.data.order.push(order_id);
                    }else{
                        passengernum = parseInt(passengernum) - passenger.length;
                        if(passengernum <= 0){
                            passengernum = 0;
                            app.poolingcar.data.passenger = [];
                            app.poolingcar.data.order = [];
                        }else{
                            $.each(passenger,function(r,val){
                                $.each(app.poolingcar.data.passenger,function(k,v){
                                    if(v==val.passenger_id){
                                        app.poolingcar.data.passenger.splice(k,1);
                                    }
                                })
                            });
                            $.each(app.poolingcar.data.order,function(r,val){
                                if(val == order_id){
                                    app.poolingcar.data.order.splice(r,1);
                                }
                            })
                        }    
                    }
                    app.poolingcar.data.passengernum = passengernum;
                    $("#carnum").html(passengernum+"/"+cartotal);
                });
            },
            poolingcarpool:function(list){
                app.poolingcar.carpoollist = list;
                $("#carpool-circuit-box").html(template('tpl-circuit',{circuit:list,name:'carpool_circuit'}));
                $("#carpool-shift-box").html(template('tpl-shift',{shift:[],name:'carpool_shift'}));
                $("#carpool-car-box").html(template('tpl-car',{car:[],name:'carpool_car'}));
                app.form.obj.render();
                if(list.length==0 && app.poolingcar.data.shift_id!=0){
                    layer.msg("没有找到适合的线路班次的车辆");
                    return false;
                }
            },
            save:function(){
                 $.post(baseUrl+'&action=carpoolsave',app.poolingcar.data,function (d) {
                    if(d.flag){
                        layer.closeAll();
                        $('#data-list').table(); 
                        layer.msg("保存成功");
                    }else{
                        layer.msg(d.msg, {icon: 5});
                        app.poolingcar.data.passenger = JSON.parse(app.poolingcar.data.passenger);
                        app.poolingcar.data.order = JSON.parse(app.poolingcar.data.order);
                        return false;
                    }
                },'json');
            }
        },
        notice:{
            list:[],
            shift:[],
            data:{
                circuit_id:0,
                shift_id:0,
                plate:'',
                address:'',
                isall:0,
                name:'',
                telephone:'',
                departuretime:''
            },
            show:function(){
                $.post(baseUrl+'&action=noticecircuit',{},function (d) {
                    if(d.flag && d.data.list!=''){
                        app.notice.list = d.data.list;
                        layer.open({
                            title:false,
                            area:['90%','80%'],
                            type:1,
                            content:template('tpl-notice', {circuit:d.data.list}),
                            success: function(layero, index){
                                app.form.obj.render();
                                var height = $("#layui-layer" + index).height() - 130;
                                $("#layui-layer" + index +" form #notice-box").css("height",height+"px");
                                var pheight = height-170;
                                $("#layui-layer" + index +" form #notice-box #order-box").css("height",pheight+"px");
                                app.notice.order([]);
                            }            
                        });

                        app.form.obj.on('select(circuit)',function(data){
                            app.notice.data.circuit_id = data.value;
                            app.notice.data.departuretime = '';
                            app.notice.data.shift_id = 0;
                            app.notice.shift = data.value == 0 ? [] : app.notice.list[data.value].list;
                            $("#shift-box").html(template('tpl-shift',{shift:app.notice.shift,name:'shift'}));
                            app.notice.order([]);
                            app.form.obj.render();
                        });
                        app.form.obj.on('select(shift)',function(data){
                            app.notice.data.shift_id = data.value;
                            app.notice.data.departuretime = data.value == 0 ? '' : app.notice.shift[data.value].departuretime;
                            var order = data.value == 0 ? [] : app.notice.shift[data.value].list;
                            app.notice.order(order);
                            app.form.obj.render();
                        });
                        app.form.obj.on('select(isall)',function(data){
                            app.notice.data.isall = data.value;
                            app.form.obj.render();
                        });
                        app.form.obj.on("submit(noticesave)",function(data){
                            if(app.notice.data.circuit_id == 0){
                                layer.msg("请选择路线", {icon: 5});
                                return false;
                            }
                            if(app.notice.data.shift_id == 0){
                                layer.msg("请选择班次", {icon: 5});
                                return false;
                            }
                            if(app.notice.data.isall == 0){
                                layer.msg("请选择发送类型", {icon: 5});
                                return false;
                            }
                            app.notice.data.address = data.field.address;
                            app.notice.data.plate = data.field.plate;
                            app.notice.data.name = data.field.name;
                            app.notice.data.telephone = data.field.telephone;
                            app.notice.save();
                            return false;
                        });
                    }else{
                        layer.msg("没有获取到能发送通告的订单", {icon: 5});
                        return false;
                    }
                },'json');
            },
            order:function(list){
                $("#order-box").html(template("tpl-notice-order",{list:list}));
            },
            save:function(){
                $.post(baseUrl+'&action=noticesave',app.notice.data,function (d) {
                    if(d.flag){
                        layer.closeAll();
                        $('#data-list').table(); 
                        layer.msg("保存成功");
                    }else{
                        layer.msg(d.msg, {icon: 5});
                        return false;
                    }
                },'json');
            }
        },
        refund:function(id){
            layer.msg("确定要给该订单退票吗？", {
                time: false, //20s后自动关闭
                btn: ['确定', '取消'],
                yes:function () {
                    $.post(baseUrl+'&action=refund',{id:id},function (d) {
                        layer.closeAll();
                        if(d.flag)
                        {
                            layer.msg('成功发起退票');
                            $('#data-list').table();
                        }else{
                            layer.msg(d.msg);
                        }
                    },'json')
                }
            });
        }
    };

    app.init();
</script>